package com.chezhujie.www.core;

import com.xy.core.utils.LocalDateTime;
import org.springframework.beans.propertyeditors.PropertiesEditor;

import java.text.ParseException;
import java.util.Date;



/**
 * 日期格式转换器
 * @author 汤伟杰
 *
 */
public class DateTypeEditor extends PropertiesEditor{


		public DateTypeEditor(){
			
		}
		/* (non-Javadoc)
		 * @see org.springframework.beans.propertyeditors.PropertiesEditor#setAsText(java.lang.String)
		 */
		@Override
		public void setAsText(String text) throws IllegalArgumentException {
			try {
				Date date = LocalDateTime.parse(text);
				if(date==null){
					setValue(null);
				}else{
					setValue(date);
				}
			} catch (ParseException ex) {
				throw new IllegalArgumentException("Could not parse date: " + ex.getMessage(), ex);
			}
		}
		
		/* (non-Javadoc)
		 * @see org.springframework.beans.propertyeditors.PropertiesEditor#setValue(java.lang.Object)
		 */
		@Override
		public void setValue(Object value) {
			// TODO Auto-generated method stub
			super.setValue(value);
		}
		
	}